package com.iflytek.uoamp.agent.monitor.lib.statics;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.iflytek.uoamp.agent.core.sender.monitorsender.requestObj.MonitorItemConfig;
import com.iflytek.uoamp.agent.core.sender.monitorsender.requestObj.MonitorItemResult;
import com.iflytek.uoamp.agent.monitor.lib.ParseLibResult;
import com.iflytek.uoamp.agent.monitor.mcagent.MonitorResultSender;

public class SataicsSender implements Runnable {

	private Statics staticer;
	public static ParseLibResult parser = new ParseLibResult();

	// 类别 依据头区分 当某种类型时应该给出错误码
	@Override
	public void run() {
		if(staticer.isSend()){
			staticer.alllock.lock();
			
			Map<String,Long> map = staticer.getAllStatics();
			
			try{
				staticer.cleanRunTime();
				staticer.clean();
			}finally{
				staticer.alllock.unlock();
			}
			
			for(String key:map.keySet()){
				StringBuffer buffer = new StringBuffer();
				buffer.append("FAILNUMBER:" + staticer.getTime4Send(key) + (char) 31);
				
				String[] keys = key.split((char) 31+"");
				//命令规则
				MonitorItemResult libResult = parser.getErrorLevel4Long(keys[1],keys[0],"FAILNUMBER",staticer.getTime4Send(key));
				List<MonitorItemResult> linked = new LinkedList<MonitorItemResult>();
				linked.add(libResult);
				List<MonitorItemConfig> uplist= MonitorResultSender.sendMonitorInfo(linked, ParseLibResult.setToString(),"checklib");
				parser.init(uplist);
			}
			
		}else{
			staticer.alllock.lock();
			try{
				staticer.addRunTime();
			}finally{
				staticer.alllock.unlock();
			}
		}
	}

}
